package org.aurora.core.biz.persistence;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.aurora.model.entity.SlotAssignInfo;

import java.util.List;

@Mapper
public interface SlotAssignMapper {
    @Update("<script>" +
            "  insert into slot_assign (slot, scheduler_ip, scheduler_port) values " +
            "   <foreach collection=\"slotAssignInfos\" item=\"slotAssignInfo\" separator=\",\">" +
            "       (#{slotAssignInfo.slot}, #{slotAssignInfo.schedulerIp}, #{slotAssignInfo.schedulerPort}) " +
            "   </foreach> " +
            "   on duplicate key update slot = values(slot), scheduler_ip = values(scheduler_ip), scheduler_port = values(scheduler_port)" +
            "</script>")
    void batchUpdateSlotAssignInfo(@Param("slotAssignInfos") List<SlotAssignInfo> slotAssignInfos);

    @Select("select slot, scheduler_ip, scheduler_port from slot_assign where slot = #{slot}")
    SlotAssignInfo querySlotAssignInfoBySlot(@Param("slot") int slot);
}
